package com.zc.service.impl;

import com.zc.dao.UserDao;
import com.zc.pojo.Dept;
import com.zc.pojo.User;
import com.zc.service.UserService;
import com.zc.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao dao;

    @Override
    public void update(User user) {
        dao.update(user);
    }

    @Override
    public List<User> query(User user) {
        return dao.query(user);
    }

    @Override
    public List<Dept> dept() {
        return  dao.dept();
    }

    @Override
    public void add(User user) {
        dao.add(user);
    }

    @Override
    public User one(User user) {
        return  dao.one(user);
    }

    @Override
    public List<Dept> queryDept(Dept dept) {
        return dao.queryDept(dept);
    }

    @Transactional
    @Override
    public void delDept(Dept dept) {
        //先删除 这个部门下的所有员工
        dao.delUserByDept(dept);
        //在删除 这个部门
        dao.delDept(dept);
    }

    @Override
    public Integer countUser(User user) {
        return  dao.countUser(user);
    }

    @Override
    public List<User> userPage(Page page, User user) {
        return dao.userPage(page,user);
    }
}
